#encoding:utf8

import os
import sys
from bs4 import BeautifulSoup as BS

from opener import LocalOpener
from parsers import get_content
opener = LocalOpener()


def main():
    USAGE = """
USAGE:
1. for test the parser
    python {0} parse url

    """.format(__file__,)
    try:
        test()
    except IndexError, ex:
        print USAGE


def test():
    # test the parser
    type = sys.argv[1]
    if type == "parse":
        test_parse()
    else:
        print("unkown type: {}".format(type))


def test_parse():
    url = sys.argv[2]
    print("test url: {}".format(url))
    print("open ... ")
    data = opener.get_source(url)
    content = data['data']
    bs = BS(content, 'lxml')
    data = get_content(url, content, bs)
    print("result:" )
    print data

main()



